/**
 * @file AmbDatum.cpp
 * Class to compute the PPP Solution.
 *
 * modification
 *
 * 2020/02/09 
 * create for ppp ambiguity selection
 * 
 * @author shjzhang 2019/07/01
 * 
 */

#include "AmbDatum.hpp"

#define debug 1

namespace gpstk
{

      // Returns a string identifying this object.
    std::string AmbDatum::getClassName() const
    { return "AmbDatum"; }

    void AmbDatum::init()
    {
        // do nothing until now
    };

    VariableDataMap AmbDatum::Prepare(VariableDataMap& ambData, 
                                      VariableDataMap& ambVarData)
    {

        double minVar(1.0E+14);
        double maxPrec(0.0);
        VariableDataMap datumData;
        Variable datumAmb;
        for(auto ad: ambData)
        {
            double ambEst = ad.second;
            double ambSig = std::sqrt(ambVarData[ad.first]);
            double precision = round.getDecision(ambEst, ambSig); 
            if(precision > maxPrec)
            {
                maxPrec = precision;
                datumAmb = ad.first;
            }
/*
            if(var < minVar)
            {
                minVar = var;
                datumAmb = ad.first;
            }
*/
        }

        datumData[datumAmb] = std::floor(ambData[datumAmb]+0.5);

        return datumData;
    }


    VariableDataMap AmbDatum::Prepare(VariableDataMap& ambData, 
                                      CovarianceDataMap& ambCovData)
    {

        double minVar(1.0E+14);
        double maxPrec(0.0);
        VariableDataMap datumData;
        Variable datumAmb;
        for(auto ad: ambData)
        {
            double ambEst = ad.second;
            double ambSig = std::sqrt(ambCovData[ad.first][ad.first]);
            double precision = round.getDecision(ambEst, ambSig); 
            if(precision > maxPrec)
            {
                maxPrec = precision;
                datumAmb = ad.first;
            }
/*
            double var = ambCovData[ad.first][ad.first];
            if(var < minVar)
            {
                minVar = var;
                datumAmb = ad.first;
            }
*/
        }

        datumData[datumAmb] = std::floor(ambData[datumAmb]+0.5);

        return datumData;
    }

}  // End of namespace gpstk
